﻿public class Solution
{
    private IList<IList<int>> result = new List<IList<int>>();
    private IList<int> path = new List<int>();
    public IList<IList<int>> FindSubsequences(int[] nums)
    {
        trackbacking(nums, 0);
        return result;
    }

    private void trackbacking(int[] nums, int start)
    {
        if (path.Count > 1)
        {
            if (path[^2] <= path[^1])
            {
                result.Add(new List<int>(path));
            }
            else
            {
                return;
            }
        }
        if (start >= nums.Length) return;
        
        // 同一层中，不使用相同元素
        HashSet<int> hused = new HashSet<int>();
        for (int i = start; i < nums.Length; i++)
        {
            if (hused.Contains(nums[i])) continue;
            hused.Add(nums[i]);
            path.Add(nums[i]);
            trackbacking(nums, i+1);
            path.RemoveAt(path.Count-1);
        }
    }

    public static void Main(string[] args)
    {
        int[] nums = [4, 6, 7, 7];
        Solution solution = new Solution();
        IList<IList<int>> result = solution.FindSubsequences(nums);
        
        // 打印
        foreach (IList<int> res in result)
        {
            foreach (int r in res)
            {
                Console.Write($"{r} ");
            }
            Console.WriteLine();
        }
    }
}